package com.major.dawn.aqs;


import java.util.concurrent.locks.ReentrantLock;

public class DeadLock {



    public static void main(String[] args) {

        ReentrantLock shui = new ReentrantLock();

        ReentrantLock xijiejing = new ReentrantLock();

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                shui.lock();
                System.out.println(Thread.currentThread().getName()+"已经占用了水龙头了");
                try {
                    Thread.sleep(10000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName()+"水已经接满了，把水龙头的位子放出来");
                shui.unlock();

                xijiejing.lock();
                System.out.println(Thread.currentThread().getName()+"已经拿到洗洁精了");
                try {
                    Thread.sleep(10000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName()+"洗洁精放回去");
                xijiejing.unlock();


            }
        });

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                xijiejing.lock();
                System.out.println(Thread.currentThread().getName()+"已经拿到洗洁精了");
                try {
                    Thread.sleep(10000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName()+"洗洁精放回去");
                xijiejing.unlock();

                shui.lock();
                System.out.println(Thread.currentThread().getName()+"已经占用了水龙头了");
                try {
                    Thread.sleep(10000);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName()+"水已经接满了，把水龙头的位子放出来");
                shui.unlock();


            }
        });

        thread.setName("xiaoming");
        thread1.setName("xiaohua");
        thread.start();
        thread1.start();

    }

}
